package com.ningxun.pagent.bus.service.basewechatuser.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningxun.pagent.bus.service.basewechatuser.IBaseWechatUserService;
import com.ningxun.pagent.bus.domain.wechatuser.BaseWechatUser;
import com.ningxun.pagent.bus.mapper.BaseWechatUserMapper;
import com.ningxun.pagent.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 青年管理模块Service业务层处理
 * 
 * @author pagent
 * @date 2025-07-09
 */
@Service
public class BaseWechatUserServiceImpl extends ServiceImpl<BaseWechatUserMapper, BaseWechatUser> implements IBaseWechatUserService
{
    @Autowired
    private BaseWechatUserMapper baseWechatUserMapper;

    /**
     * 查询青年管理模块
     * 
     * @param userId 青年管理模块主键
     * @return 青年管理模块
     */
    @Override
    public BaseWechatUser selectBaseWechatUserByUserId(Long userId)
    {
        return baseWechatUserMapper.selectBaseWechatUserByUserId(userId);
    }

    /**
     * 根据openid查询该用户是否存在
     *
     * @param openid 青年管理模块
     * @return 青年管理模块
     */
    @Override
    public BaseWechatUser queryBaseWechatUserByopenid(String openid){
        LambdaQueryWrapper<BaseWechatUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BaseWechatUser::getOpenId, openid);
        return this.getOne(wrapper);
    }




    /**
     * 查询青年管理模块列表
     * 
     * @param baseWechatUser 青年管理模块
     * @return 青年管理模块
     */
    @Override
    public List<BaseWechatUser> selectBaseWechatUserList(BaseWechatUser baseWechatUser)
    {
        return baseWechatUserMapper.selectBaseWechatUserList(baseWechatUser);
    }

    /**
     * 新增青年管理模块
     * 
     * @param baseWechatUser 青年管理模块
     * @return 结果
     */
    @Override
    public int insertBaseWechatUser(BaseWechatUser baseWechatUser)
    {
        baseWechatUser.setCreateTime(DateUtils.getNowDate());
        return baseWechatUserMapper.insertBaseWechatUser(baseWechatUser);
    }

    /**
     * 修改青年管理模块
     * 
     * @param baseWechatUser 青年管理模块
     * @return 结果
     */
    @Override
    public int updateBaseWechatUser(BaseWechatUser baseWechatUser)
    {
        baseWechatUser.setUpdateTime(DateUtils.getNowDate());
        return baseWechatUserMapper.updateBaseWechatUser(baseWechatUser);
    }

    @Override
    public boolean updataStatusByuserid(long id , long userStatus){
        LambdaUpdateWrapper<BaseWechatUser> wrapper = new LambdaUpdateWrapper<BaseWechatUser>();
            wrapper
                    .set(BaseWechatUser::getUserStatus , userStatus )
                    .eq(BaseWechatUser::getUserId , id);
        return this.update(wrapper);
    }
    /**
     * 批量删除青年管理模块
     * 
     * @param userIds 需要删除的青年管理模块主键
     * @return 结果
     */
    @Override
    public int deleteBaseWechatUserByUserIds(Long[] userIds)
    {
        return baseWechatUserMapper.deleteBaseWechatUserByUserIds(userIds);
    }

    /**
     * 删除青年管理模块信息
     * 
     * @param userId 青年管理模块主键
     * @return 结果
     */
    @Override
    public int deleteBaseWechatUserByUserId(Long userId)
    {
        return baseWechatUserMapper.deleteBaseWechatUserByUserId(userId);
    }

    @Override
    public void updateBaseWechatAvatar(BaseWechatUser baseWechatUser) {
        baseWechatUserMapper.updateBaseWechatAvatar(baseWechatUser);
    }
}
